using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class NativeCtrl : MonoBehaviour
{
    private AndroidJavaClass _mlJavaClass = null;
    private static NativeCtrl _instance;
    private Action<bool> _callback;
    public static NativeCtrl Instance
    {
        get { return _instance; }
    }

    private void Awake()
    {
        _instance = this;
#if UNITY_ANDROID && !UNITY_EDITOR
        _mlJavaClass = new AndroidJavaClass("com.plugIn.TestShowAd");
#endif
    }

    public void ShowAD(Action<bool> action)
    {
        _callback = action;
#if UNITY_ANDROID && !UNITY_EDITOR
        _mlJavaClass.CallStatic("ShowAd");
#endif
    }

    public void OnShowAdCallBack(string resultCode)
    {
        int.TryParse(resultCode, out int code);
        _callback?.Invoke(code == 1);
        _callback = null;
    }
}
